
window.onload = function(){
    document.querySelector('.back-to-top')?.addEventListener('click', function() {
        // 平滑滚动到页面顶部
        window.scrollTo({
            top: 0,
            behavior: 'smooth'
        });
    });
    
    headerActive()
}

// 让header的nav-item高亮
function headerActive() {
    const urlParams = new URLSearchParams(window.location.search);
    let name = urlParams?.get('name');
    let headerList = document.querySelectorAll('header nav .nav-item a')
    // console.log('===>', headerList.length, headerList, name, urlParams);
    headerList?.forEach((item, index) => {
        // console.log(item?.href,item.textContent,name, item?.href?.endsWith('/portal'), item?.href?.includes(name))
        if ((item?.href?.endsWith('/portal') && !name) || item?.href?.includes(name)) {
            item.classList.add('active')
        } else {
            item.classList.remove('active')
        }
    })
}